{template header}
<div class="container">

<div class="row">

<div class="col-md-8">

    <div class="panel panel-default">
        <div class="panel-body">
            {template top}
        </div>
    </div>



    <div class="panel panel-default" id="info">
        <div class="panel-body" style="position: relative;">

            {if $GLOBALS['TS_USER']!=''&&($strGroupUser['isadmin']==1|| $TS_USER[userid] == $strGroup[userid]|| $GLOBALS['TS_USER']['isadmin']==1)}
            <div style="position: absolute;right: 15px;top: 15px;">
                {if !isMobile()&& ($GLOBALS['TS_USER']['isadmin']=='1'||$isleader) }<a class="btn btn-success"  href="{tsUrl('group','do',array('ts'=>'output','groupid'=>$groupid,'begintime'=>$begintime,'endtime'=>$endtime))}">导出</a>&nbsp;&nbsp;
                {/if}
                <a class="btn btn-success"  data-toggle="modal" data-target="#do_acount_form">记账</a>
                <li style="float: right">
                    <a  class="btn btn-block" onclick="openform()"><i class="fa fa-filter"></i></a>
                </li>
            </div>

            {/if}
            <ul class="nav nav-pills">
            {if $strGroup['isplace']>0}
            {if !isMobile()}
            <li role="presentation"><a href="{tsUrl('group','show',array('id'=>$strGroup[groupid]))}#info">文档</a></li>
            <li role="presentation" ><a href="{tsUrl('group','duty',array('id'=>$strGroup[groupid]))}#info">服务</a></li>
            <li role="presentation" class="active"><a href="{tsUrl('group','acount',array('id'=>$strGroup[groupid]))}#info">账目</a></li>
            {else}
            <li>
                <select onchange="jump(this.options[this.options.selectedIndex].value)" name="typeid" id="typeid" class="form-control">
                    <option value="{tsUrl('group','show',array('id'=>$strGroup[groupid]))}#info">文档</option>
                    <option value="{tsUrl('group','duty',array('id'=>$strGroup[groupid]))}#info" >服务</option>
                    <option value="{tsUrl('group','acount',array('id'=>$strGroup[groupid]))}#info"  selected>账目</option>
                </select>
            </li>
            {/if}
            {/if}
            </ul>
            <!--筛选-->
            <form id="selectform" class="searchform" method="get" action="{tsUrl('group','acount',array('page'=>$page))}"  enctype="multipart/form-data" style="display: none;">
                <ul style="padding:10px;display: flex">
                    <input type="hidden" name="app" value="group">
                    <input type="hidden" name="ac" value="acount">
                    <input type="hidden" name="page" value="{$page}">
                    <input type="hidden" name="id" value="{$strGroup[groupid]}">

                    <li style="padding-right: 2px">
                        <input class="form-control" name="begintime" readonly value="{if $begintime} {$begintime}{/if}"  id="beginTime" placeholder="开始时间"/>
                    </li>
                    <li style="padding-right: 2px">
                        <input class="form-control" name="endtime" readonly value="{if $endtime} {$endtime}{/if}" id="endTime"  placeholder="结束时间"/>
                    </li>
                    <li style="padding-right: 2px">
                        <input class="btn btn-group-sm" type="submit" value="查询">
                    </li>

                </ul>
            </form>
<div class="topic_list">
<ul>
<li>
    <div class="topic_title">
收入合计：{$strGroup[income]}元，支出合计：{$strGroup[outcome]}元，结余：{$strGroup[surplus]}元
    </div>
</li>
{loop $arrAcount $key $item}
<li>


<div class="topic_title">


<span style="float:left;">
{php echo date('Y-m-d',$item[addtime])}&nbsp;&nbsp;

{if $item[type]==0}支出{else}收入{/if}{$item[num]}元&nbsp;&nbsp;

备注：{$item[memo]}
</span>
    {if $GLOBALS[TS_USER][userid]==$item['userid']}
       &nbsp;&nbsp; <a  href="javascript:void('0');" onclick="delAcount('{$item['acountid']}')"><i class="fa fa-trash"></i> </a>
      {/if}
    {if $item[url]!=''}
    &nbsp;&nbsp; <a  target="_blank" href="uploadfile/group/{$item[url]}" ><i class="fa fa-link"></i> </a>
    {/if}
<span style="float:right;">
记账：<a href="{tsUrl('user','duty',array('id'=>$item[userid]))}"  rel="face" uid="{$item['user']['userid']}">{$item[user][username]}</a>


</span>

</div>

</li>
{/loop}

</ul>
</div>
<div class="page">{$pageUrl}</div>
</div>
</div>
</div>
    {template right}
</div>
</div>


<div id="do_acount_form" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true" >
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h5 class="modal-title">记账</h5>
            </div>

            <div class="modal-body" >

                <form  id="record" class="form-horizontal" method="post" action="{SITE_URL}index.php?app=group&ac=do&ts=addacount" enctype="multipart/form-data">


                    <input type="hidden" id="groupid" name="groupid" value="{$strGroup[groupid]}">


                    <div class="form-group">
                        <label class="col-sm-3 control-label">属性</label>
                        <div class="col-sm-9">
                            <input type="radio" name="type" value="0" />支出 <input  type="radio"  name="type" value="1" />收入
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">发生日期</label>
                        <div class="col-sm-9">
                        <input class="form-control" name="addTime" readonly value="" id="addTime" />
                            </div>
                    </div>


                    <div class="form-group">
                        <label class="col-sm-3 control-label">金额</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" name="num" id="num">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">明细</label>
                        <div class="col-sm-9" ><textarea rows="5" id="memo" name="memo" class="form-control" ></textarea>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">附件</label>
                        <div class="col-sm-9" >
                            <input type="file" name="attachment"  datatype="*4-50" />
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">

                            <button data-id="submit" type="submit" class="btn btn-success">点击提交</button>
                        </div>
                    </div>
                </form>


            </div>
        </div>
    </div>
</div>



<div class="modal fade" id="upload" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <form class="form-horizontal ajaxForm2" id='formadd'  method="post" enctype="multipart/form-data" action="{SITE_URL}index.php?app=group&ac=do&ts=upload_excel">
        <div class="modal-dialog" >
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                            aria-hidden="true">×
                    </button>
                    <h4 class="modal-title" id="myModalLabel">
                        导入Excel
                    </h4>
                </div>

                <div class="modal-body">
                    <div class="row">
                        <div class="col-xs-12">


                            <div class="form-group">

                                <div class="col-sm-9">
                                    <input type="file" name="excelData"  multiple="true" datatype="*4-50" />
                                    <span class="Validform_checktip"></span>

                                </div>
                            </div>


                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="submit" id='formbtn'  class="btn btn-primary">
                        提交保存
                    </button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        关闭
                    </button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </form>
</div><!-- /.modal -->




<script>

    $('#addTime').datetimepicker({
        language:  'zh-CN',
        format: 'yyyy-mm-dd',
        autoclose: true,
        endDate:new Date(),
        minView:2
    });

    $('#beginTime').datetimepicker({
        language:  'zh-CN',
        format: 'yyyy-mm-dd',
        autoclose: true,
        endDate:new Date(),
        minView:2
    });

    $('#endTime').datetimepicker({
        language:  'zh-CN',
        format: 'yyyy-mm-dd',
        autoclose: true,
        endDate:new Date(),
        minView:2
    });


    //删除账目
    function delAcount(acountid){


        if (confirm('删除这条记录吗？')) {

            $.ajax({
                type: "POST",
                url: siteUrl+"index.php?app=group&ac=do&ts=delacount",
                data: "acountid="+acountid,
                beforeSend:function(){
                },
                success:function(result){
                    if(result == '1'){
                        window.location.reload();
                    }
                }
            });

        }
    }

    $(function(){
        $('#record').on('submit', function(e) {

            var groupid  = $('#goupid').val();

            var addtime  = $('#addTime').val();
            var type  = $('input[name="type"]:checked').val();
            var num  = $('#num').val();
            var memo  = $('#memo').val();

            if (type == undefined) {
                bootbox.alert('属性不能为空');
                return false;
            }

            if (addtime == '') {
                bootbox.alert('日期不全');
                return false;
            }

            if (num == '') {
                bootbox.alert('金额不能为空');
                return false;
            }

             if (memo == '') {
             bootbox.alert('明细不能为空');
             return false;
             }

            $('#do_acount_form').modal('hide');
            location.reload();

        });




    });



    $(document).ready(function(e) {
        var date = new Date();
        var vYear = date.getFullYear();
        var vMon = date.getMonth() + 1;
        var vDay = date.getDate();
        var year;
        var month;
        var day;
        var str_year;
        var str_month;
        var t_month;
        var str_day;

        {if $myDuty!=''}
            vYear = {php echo date('Y',$myDuty['begintime'])};
            vMon  = {php echo date('m',$myDuty['begintime'])};
            vDay  = {php echo date('d',$myDuty['begintime'])};
            {/if}

                var first_year = date.getFullYear()-1;
//起始
                var last_year = date.getFullYear();
//终止年
                var t_year
                var i;
                var r;
                var y_v;
                var m_v;
                var d_v;
//写出年的选项
                $("[data-name=year]").append('<option value=""></option>');
                for (i = last_year; i >= first_year; i--) {

                    if (i != vYear) {
                        $("[data-name=year]").append('<option value="' + i + '">' + i + '</option>');
                    } else {
                        $("[data-name=year]").append('<option value="' + i + '" selected>' + i + '</option>');
                    }
                }
//写出月的选项
                $("[data-name=month]").append('<option value=""></option>');
                for (i = 1; i <= 12; i++) {
                    r = i ;
                    if (i != vMon) {
                        $("[data-name=month]").append('<option value="' + i + '">' + r + '</option>');
                    } else {
                        $("[data-name=month]").append('<option value="' + i + '" selected>' + r + '</option>');
                    }
                }

//初始化日的值
                day();
//在年月的值发生变化时计算日期的天数
                $("[data-name=year]").change(function(){   day();   });
                $("[data-name=month]").change(function(){ day();
                });
//根据日期的天数，输出日选项

                function day(){
                    var y_v=$("[data-name=year]").val();
                    var m_v=$("[data-name=month]").val()-1;
                    var d_v;
                    var i;
                    if((y_v%100!=0&&y_v%4==0)||y_v%400==0) {
                        d_v=new Array(31,29,31,30,31,30,31,31,30,31,30,31);
                    }    else   {
                        d_v=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
                    }
                    $("[data-name=day]").html("");
                    $("[data-name=day]").append('<option value=""></option>');
                    for(i=1;i<=d_v[m_v];i++)   {
                        //if(i!=vDay)  {
                        $("[data-name=day]").append('<option value="'+i+'">'+i+'</option>');
                        //	}  else {
                        //	$("[data-name=day]").append('<option value="'+i+'" selected>'+i+'</option>');
                        //	}
                    }
                }
            });


</script>

{template footer}